#!/bin/bash

#echo "Enter directory\n"
#read directory
userdir=`whoami`
#echo $userdir
dir_name=/Users/${userdir}/learnShell/filesToMakeIndex

function add_result(filename,filesize,duration){
		echo "  ${filename}  ${filesize}  ${duration}"
}

function get_file_size(file){
	return `wc -c < $file`
}

function get_duration(file){
	duration=""
	extension="${file##*.}"
	for i in mpe mpeg mpg avi mov qt vdo viv vivo movie flv
	do
		if [ $extension -eq i]; then
			flag=1
			break
		fi
		
	done
	if [flag]; then
		return `ffmpeg -i $file`
	else
		return $duration
	fi

}

`basename $dir_name | tr [a-z] [A-Z] > dir_index_file.txt`
duration=""
MOVIES=(mpe mpeg mpg avi mov qt vdo viv vivo movie flv)

for file in `find $dir_name | grep -v ^l`
do
	
	filename=`basename $file`
	filename="${file%.*}"
	extension="${file##*.}"
	echo "${filename}"
	echo "${extension}"


	if [ -d $file ] ; then 
		echo $filename
	else
		#filesize=`wc -c < $file`
	filesize=get_file_size $file
		
		#duration=get_duration $file
		
		add_result $filename $filesize $duration
	fi
	
	#name=${file%%[.]*}
	 # echo $name
	#\t $name\n >> dir_index_file.txt
done
cat dir_index_file.txt
#mv $result $dir_name."_index.txt"

